<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    let obj = {
        uname: '张三丰',
        age: 22,
        sex: '男',
        color: ['red', 'blue', 'pink', 'yellow'],
        message: {
            index: 10,
            score: 99,
            look: { yi: 1, er: 2, san: { si: 5 } }
        }
    }
    let newObj = {}
    function kaobei(newObj, obj) {
        for (let key in obj) {
            if (obj[key] instanceof Array) {//obj[key]是数组
                newObj[key] = []
                //假如数组里嵌套数组，用递归实现深拷贝
                kaobei(newObj[key], obj[key])
            } else if (obj[key] instanceof Object) {
                newObj[key] = {}
                //假如对象里嵌套对象，用递归实现深拷贝
                kaobei(newObj[key], obj[key])
            } else {
                newObj[key] = obj[key]
            }
        }
    }
    kaobei(newObj, obj)
    obj.message.score = 100
    console.log(obj, newObj)
</script>

</html>